package com.LeeCode;

/**
 * 按位与最大的最长子数组
 */

public class Code2419 {
    public static void main(String[] args) {
        int[] nums = {96317, 96317, 96317, 96317, 96317, 96317, 96317, 96317, 96317, 279979};
        System.out.println(new Code2419().longestSubarray(nums));
    }

    public int longestSubarray(int[] nums) {
        int maxNum = 0, maxLength = 0;
        int currentLength = 0;

        for (int num : nums) {
            if (num > maxNum) {
                // 发现新的最大值，重置所有状态
                maxNum = num;
                currentLength = 1;
                maxLength = 1;
            } else if (num == maxNum) {
                // 继续当前最大值的连续序列
                currentLength++;
                maxLength = Math.max(maxLength, currentLength);
            } else {
                // 中断连续序列
                currentLength = 0;
            }
        }
        return maxLength;
    }
}
